<?php

class ResellerController extends Controller
{
	public function actionIndex()
	{
		$this->render('index');
	}

	/**
	 * methodDescription.
	 *
	 * @return returnType returnDescription
	 */
	public function filters() {
		return array(
	    	'accessControl',
			//'checkAccess',
		);
	}

	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules()
	{
		return array(
			array('allow',  // allow all users to perform 'index' and 'view' actions
					'actions'=>array('index','view'),
					'users'=>array('@'),
					'expression'=>'$user->role=="reseller"',
			),
			array('allow', // allow authenticated user to perform 'create' and 'update' actions
					'actions'=>array('create','update'),
					'users'=>array('@'),
			),
			array('allow', // allow admin user to perform 'admin' and 'delete' actions
					'actions'=>array('admin','delete'),
					'users'=>array('admin'),
			),
			array('deny',  // deny all users
					'users'=>array('*'),
			),
		);
	}

	public function filterCheckAccess($filterChain)
	{
		//var_dump(Yii::app()->user->role); die;
		if(Yii::app()->user->role !== 'reseller')
		{
			$this->redirect(Yii::app()->homeUrl);
		}
		$filterChain->run();
	}
}